//
//  GJViewController.m
//  GJNK
//
//  Created by xmdfst on 16/10/13.
//  Copyright © 2016年 LYX. All rights reserved.
//

#import "DFViewController.h"
#import "RootViewController.h"


static RootViewController *g_rootViewController = nil;

@interface DFViewController ()<UINavigationControllerDelegate,UIGestureRecognizerDelegate>


@property (nonatomic,strong) UIBarButtonItem *barButtonBack;

@end

@implementation DFViewController 

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.backBarButtonItem = self.barButtonBack;
    // 设置导航控制器的代理为self
   self.navigationController.delegate = self;
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;// 这个方法是会同时清空角标和通知中心的
    self.navigationController.interactivePopGestureRecognizer.enabled = NO; //禁用系统的滑动
//    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleNavigationTransition:)];
    UISwipeGestureRecognizer *right = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleNavigationTransition:)];
    right.direction = UISwipeGestureRecognizerDirectionRight;
    // 设置手势代理，拦截手势触发
    right.delegate = self;
    // 给导航控制器的view添加全屏滑动手势
    [self.view addGestureRecognizer:right];
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    // 注意：只有非根控制器才有滑动返回功能，根控制器没有。
    
    // 判断导航控制器是否只有一个子控制器，如果只有一个子控制器，肯定是根控制器
    if(self.navigationController.childViewControllers.count == 1){
        // 表示用户在根控制器界面，就不需要触发滑动手势，
        return NO;
    }
    return YES;
}
-(void)handleNavigationTransition:(UIPanGestureRecognizer *)g{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - Action
-(NSString *)getNowTimeTimestamp3{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss SSS"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    //设置时区,这个对于时间的处理有时很重要
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    
    [formatter setTimeZone:timeZone];
    
    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]*1000];
    
    return timeSp;
    
}

/**
 *  @author LYX, 16-10-19 17:10:14
 *
 *  pop出控制器调用的方法
 */
-(void)onBack
{
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - UI
-(UIBarButtonItem*)barButtonBack
{
    if (_barButtonBack == nil) {
        _barButtonBack = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(onBack)];
    }
    return _barButtonBack;
}



@end
